setwd ("/Users/mincho/Library/Mobile Documents/com~apple~CloudDocs/1. Work/random test/Blankenship.ISQ-2023-05-0271.R2")
#TABLE 2#


rm(list=ls())
set.seed(19) # Set seed
install.packages("randomizr")
library(randomizr)    # randomizr package for complete random assignment
library(ggplot2)
library(mediation)
library(mediations)
library(foreign)
library(readxl)
data <- read.csv("ReplicationData_Mediation.csv")


set.seed(19) # Set seed
model.m <- lm(threatperception ~ treatment_reassurance + treatment_abandon + treatment_conditional +  treatment_domestic +  treatment_normative +  treatment_shaming + country_id, data=data)
model.y <- lm(defensespend ~ treatment_reassurance + treatment_abandon + treatment_conditional +  treatment_domestic +  treatment_normative +  treatment_shaming + threatperception + country_id, data=data)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_abandon", mediator = "threatperception")
summary(mediate)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_conditional", mediator = "threatperception")
summary(mediate)


model.m <- lm(confidence_us ~ treatment_reassurance + treatment_abandon + treatment_conditional +  treatment_domestic +  treatment_normative +  treatment_shaming + country_id, data=data)
model.y <- lm(defensespend ~ treatment_reassurance + treatment_abandon + treatment_conditional +  treatment_domestic +  treatment_normative +  treatment_shaming + confidence_us + country_id, data=data)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_abandon", mediator = "confidence_us")
summary(mediate)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_conditional", mediator = "confidence_us")
summary(mediate)

model.m <- lm(moralobligation ~ treatment_reassurance + treatment_abandon + treatment_conditional +  treatment_domestic +  treatment_normative +  treatment_shaming + country_id, data=data)
model.y <- lm(defensespend ~ treatment_reassurance + treatment_abandon + treatment_conditional +  treatment_domestic +  treatment_normative +  treatment_shaming + moralobligation + country_id, data=data)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_abandon", mediator = "moralobligation")
summary(mediate)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_conditional", mediator = "moralobligation")
summary(mediate)

model.m <- lm(reactance ~ treatment_reassurance + treatment_abandon + treatment_conditional +  treatment_domestic +  treatment_normative +  treatment_shaming + country_id, data=data)
model.y <- lm(defensespend ~ treatment_reassurance + treatment_abandon + treatment_conditional +  treatment_domestic +  treatment_normative +  treatment_shaming + reactance + country_id, data=data)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_abandon", mediator = "reactance")
summary(mediate)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_conditional", mediator = "reactance")
summary(mediate)



#TABLE A8#
set.seed(19) # Set seed
model.m <- lm(threatperception ~ treatment_reassurance + treatment_abandon + treatment_conditional +  treatment_domestic +  treatment_normative +  treatment_shaming + country_id, data=data)
model.y <- lm(defensespend ~ treatment_reassurance + treatment_abandon + treatment_conditional +  treatment_domestic +  treatment_normative +  treatment_shaming + threatperception + country_id, data=data)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_reassurance", mediator = "threatperception")
summary(mediate)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_domestic", mediator = "threatperception")
summary(mediate)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_normative", mediator = "threatperception")
summary(mediate)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_shaming", mediator = "threatperception")
summary(mediate)

model.m <- lm(confidence_us ~ treatment_reassurance + treatment_abandon + treatment_conditional +  treatment_domestic +  treatment_normative +  treatment_shaming + country_id, data=data)
model.y <- lm(defensespend ~ treatment_reassurance + treatment_abandon + treatment_conditional +  treatment_domestic +  treatment_normative +  treatment_shaming + confidence_us + country_id, data=data)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_reassurance", mediator = "confidence_us")
summary(mediate)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_domestic", mediator = "confidence_us")
summary(mediate)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_normative", mediator = "confidence_us")
summary(mediate)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_shaming", mediator = "confidence_us")
summary(mediate)

model.m <- lm(moralobligation ~ treatment_reassurance + treatment_abandon + treatment_conditional +  treatment_domestic +  treatment_normative +  treatment_shaming + country_id, data=data)
model.y <- lm(defensespend ~ treatment_reassurance + treatment_abandon + treatment_conditional +  treatment_domestic +  treatment_normative +  treatment_shaming + moralobligation + country_id, data=data)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_reassurance", mediator = "moralobligation")
summary(mediate)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_domestic", mediator = "moralobligation")
summary(mediate)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_normative", mediator = "moralobligation")
summary(mediate)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_shaming", mediator = "moralobligation")
summary(mediate)

model.m <- lm(reactance ~ treatment_reassurance + treatment_abandon + treatment_conditional +  treatment_domestic +  treatment_normative +  treatment_shaming + country_id, data=data)
model.y <- lm(defensespend ~ treatment_reassurance + treatment_abandon + treatment_conditional +  treatment_domestic +  treatment_normative +  treatment_shaming + reactance + country_id, data=data)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_reassurance", mediator = "reactance")
summary(mediate)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_domestic", mediator = "reactance")
summary(mediate)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_normative", mediator = "reactance")
summary(mediate)
set.seed(19) # Set seed
mediate <- mediate(model.m, model.y, sims = 1000, treat = "treatment_shaming", mediator = "reactance")
summary(mediate)